#include <stdio.h>

// 定义状态枚举类型
typedef enum {
    STATE_INIT,
    STATE_RUNNING,
    STATE_STOPPED
} State;

// 定义状态函数指针类型
typedef void (*StateFunction)(void);

// 状态函数
void stateInit(void);
void stateRunning(void);
void stateStopped(void);

int main(void) {
    State state = STATE_INIT;
    StateFunction stateFunction;

    while (1) {
        // 根据当前状态选择相应的状态函数
        switch (state) {
            case STATE_INIT:
                stateFunction = stateInit;
                break;
            case STATE_RUNNING:
                stateFunction = stateRunning;
                break;
            case STATE_STOPPED:
                stateFunction = stateStopped;
                break;
        }

        // 执行状态函数
        stateFunction();
    }

    return 0;
}

void stateInit(void) {
    printf("Initializing...\n");
    // 设置下一个状态
    state = STATE_RUNNING;
}

void stateRunning(void) {
    printf("Running...\n");
    // 设置下一个状态
    state = STATE_STOPPED;
}

void stateStopped(void) {
    printf("Stopped.\n");
    // 设置下一个状态
    state = STATE_INIT;
}

